/* 多类型约束接口 */

interface A {
  getName(): string;
}

interface B {
  getAge(): number;
}

/*泛型*/

// type AB = A | B;
// 接口可以多继承
interface AB extends A, B {

}

class Demo<T extends AB> {
  private ab: T

  constructor(ab: T) {
    this.ab = ab
  }

  /*多类型约束*/
  getT() {
    this.ab.getAge();
    this.ab.getName();
  }
}


class Test implements AB {
  getAge(): number {
    console.log('Test中的getAge')
    return 0;
  }

  getName(): string {
    console.log('Test中的getName')
    return "";
  }
}

let test = new Test()
let demo = new Demo(test);
demo.getT();

